#include <string>
#include <unordered_map>

using namespace std;

class Solution
{
public:
    int lengthOfLongestSubstring(string s)
    {
        unordered_map<char, int> m;
        int right = 0, left = 0;
        int ret = 0;
        while (right < s.size())
        {
            ++m[s[right]];
            while (m[s[right]] > 1)
            {
                --m[s[left]];
                ++left;
            }
            ret = max(ret, right - left + 1);
            ++right;
        }
        return ret;
    }
};